<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/jsp/common/common.jsp"%>  

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
    content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui-mobile/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui-mobile/themes/mobile.css"/>">
<link rel="stylesheet" type="text/css"
    href="<c:url value="/static/jquery-easyui-mobile/themes/icon.css"/>">


<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui-mobile/jquery.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui-mobile/jquery.easyui.mobile.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui-mobile/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/static/js/common.js"/>"></script>


<script type="text/javascript">


    function initList(listDisplayEId) {
        $('#' + listDisplayEId).datagrid({
              url : "<c:url value='/distributor/findDistributorDetailOrder.do'/>" +"?ordId=${OrderDistributorPo.ordId }&ordSupId=${OrderDistributorPo.ordSupId }"
        });
    };
    function searchInfo(){
        var date = $('#ordDate').datebox('getValue');
            $('#dg').datagrid('reload', {
                ordDate:date
        }); 
            
    }
    $(document).ready(function() {
        initList('dg');
    });
        
    var editIndex = undefined;
    function endEditing(){
        if (editIndex == undefined){return true}
        if ($('#dg').datagrid('validateRow', editIndex)){
            $('#dg').datagrid('endEdit', editIndex);
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }

    function onClickRow(index){
        if (editIndex != index){
            if (endEditing()){
                $('#dg').datagrid('selectRow', index)
                        .datagrid('beginEdit', index);
                editIndex = index;
            } else {
                $('#dg').datagrid('selectRow', editIndex);
            }
        }
    }
    function removeit() {
        if (editIndex == undefined) {
            return
        }
        $('#dg').datagrid('cancelEdit', editIndex).datagrid('deleteRow',
                editIndex);
        editIndex = undefined;
    }
    
    var xhr;
    function commit() {
    	alert("微信暂不开放此功能！");
    	return;
    	var rows = $('#dg').datagrid('getRows');
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
            //生成json数据
            var materOrderList = new Array();
            var jsonFater;
            for (var i = 0; i < rows.length; i++) {
                var rowIndex = $('#dg').datagrid('getRowIndex',
                        rows[i]['ordDistributorMaterId']);
                $('#dg').datagrid('endEdit', rowIndex);
                
                
                var jsonSun = "{ordMaterId:'" + rows[i]['ordMaterId'] 
                        + "',ordMaterLevel:'" + rows[i]['ordMaterLevel']
                        + "',ordDistributorMaterId:'" + rows[i]['ordDistributorMaterId'] 
                        + "',ordMaterWeightReality:'" + rows[i]['ordMaterWeightReality'] 
                        + "',ordMaterValueUnit:'" + rows[i]['ordMaterValueUnit'] + "'}";
                materOrderList.push(jsonSun);
                
            }
            //beginEditList(rows, '#dg', 'ordSupMaterId');

            jsonFater = JSON.stringify(materOrderList);
            var form = new FormData();
            //ajax 提交表单数据
            form.append("ordId", "${OrderDistributorPo.ordId }"); // 可以增加表单数据
            form.append("ordSupId", "${OrderDistributorPo.ordSupId }"); // 可以增加表单数据
            form.append("materdategridList", jsonFater); // 可以增加表单数据
            // XMLHttpRequest 对象
            xhr = new XMLHttpRequest();
            xhr.onreadystatechange = xhr_return;
            xhr.open("post", '<c:url value='/distributorForSup/updateMaterWeightAndMaterValueForDistributorAndSup.do'/>', true);
            /*xhr.onload = function(a) {
                $.messager.alert('系统提示', '修改成功', 'info', function() {
                    $('#'+listDisplayEId).datagrid('reload');
                    $('#'+listDisplayEId).datagrid('clearSelections');
                });
            };  */
            xhr.send(form);
        }
    	
    }
    function xhr_return() {
        if (xhr.readyState == 4) {// 4 = "loaded"

            if (xhr.status == 200) {// 200 = OK
                var data;
                data = xhr.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                if (data.success) {
                    $.messager.alert("提示", "价格提交完毕！", 'info');
                    $('#dg').datagrid('clearSelections');

                    $('#dg').datagrid('reload');
                } else {
                    $.messager.alert("提示", data.msg, 'info');
                }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
    
</script>
<body>
    <table id="dg"
        data-options="
                header:'#hh',
                iconCls: 'icon-edit',
                singleSelect: true,
                fit:true,
                fitColumns:true,
                border: false,
                nowrap : false,
                scrollbarSize: 0,
                rownumbers:true,
                onClickRow:onClickRow,
                idField:'ordDistributorMaterId'
            ">
        <thead>
            <tr>
                <th data-options="field:'id',hidden:true">序号</th>
                <th data-options="field:'ordDistributorMaterId',hidden:true">ID</th>
                <th data-options="field:'ordId',hidden:true">订单号</th>
                <th data-options="field:'ordSupId',hidden:true">供货商id</th>
                <th data-options="field:'ordSupName',hidden:true">供货商id</th>
                <th data-options="field:'ordMaterId',hidden:true">材料id</th>
                <th data-options="field:'materName',width:80">材料名</th>
                <th data-options="field:'materType',width:30,formatter:formatFoodType1">种类</th>
                <th data-options="field:'ordMaterLevel',hidden:true">材料品级</th>
                <th data-options="field:'brands',width:30">品牌</th>
                <th data-options="field:'specifications',width:50">规格</th>
                <th data-options="field:'ordMaterWeight',width:30,hidden:true">需求量</th>
                <th data-options="field:'ordMaterWeightReality',width:30,editor:{  type:'numberbox', options: {   precision:2  }  }">数量</th>
                <th data-options="field:'unit',width:30">单位</th>
                <th data-options="field:'ordMaterValueUnit',width:30,editor:{  type:'numberbox', options: {   precision:2  }  }  ">单价</th>
                <th data-options="field:'ordMaterValue',width:30">总价</th>
                <th data-options="field:'code',width:30">摊位</th>
                

            </tr>
        </thead>
    </table>
    <div id="hh">
        <div class="m-toolbar">
            <div class="m-left">
                <li style="line-height: 32px; font-size: 16px; font-weight: bold;" value="${shopName }">${shopName }
                    
                </li>
            </div>
            <div class="m-right">
                <a href="javascript:void(0)" class="easyui-linkbutton"
                    data-options="iconCls:'icon-save',plain:true"
                    onclick="commit()">提交数量和单价</a> 
            </div>
        </div>
    </div>

</body>
</html>